package com.xiaoxie.cloud.controller;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PathVariable;

@Component
@Slf4j
public class FallbackHandler {

    // 静态方法
    public static String handleException(BlockException ex) {
        log.error("资源被限流: {}", ex.getMessage());
        return "资源被限流，请稍后再试";
    }

    public static String handleActionException(Integer p1, BlockException ex) {
        log.error("资源被限流: {}", ex.getMessage());
        return "资源被限流，请稍后再试";
    }

    // 这里指定Throwable参数是为了捕获程序逻辑异常
    public static String handleActionFallback(Integer p1, NullPointerException ex) {
        log.error("程序逻辑异常: {}", ex.getMessage());
        return "程序逻辑异常了" + "\t" + ex.getMessage();
    }
}
